'use client';

import { useEffect } from 'react';
import { useParams, useRouter } from 'next/navigation';
import Logo from '@/app/component/Logo';
import useAuth from '@/hooks/useAuth';
import { isSocialLoginProvider, SOCIAL_PROVIDER_LABELS } from '@/constants/social';

/**
 * 소셜 로그인 완료 페이지 (Naver/Kakao) — /login/{provider}/complete
 * 콜백 라우트가 httpOnly 쿠키(accessToken/refreshToken)를 심은 뒤 도착.
 * 기존 /login/google/complete 와 동일하게 login() 으로 프로필 조회 + 메인 이동.
 */
export default function Page()
{
	const { login } = useAuth();
	const router = useRouter();
	const params = useParams<{ provider: string }>();
	const label = isSocialLoginProvider(params.provider) ? SOCIAL_PROVIDER_LABELS[params.provider] : null;

	useEffect(() => {
		if (!label) {
			router.replace('/login');
			return;
		}
		login(true);
	// eslint-disable-next-line react-hooks/exhaustive-deps
	}, []);

	return (
		<div className="fixed inset-0 flex flex-col items-center justify-center gap-6 bg-[var(--bg-page)] z-50">
			<span className="auth-logo inline-block">
				<Logo size="lg" />
			</span>
			<div className="w-7 h-7 border-[3px] border-gray-200 border-t-[var(--color-accent)] rounded-full animate-spin" />
			<p className="text-sm text-[var(--text-muted)]">{label ?? '소셜'} 로그인 중...</p>
		</div>
	);
}